package com.cwf.system.vo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.cwf.system.entity.Dictionary;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;

@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class DictionaryVO  {
    //id@TableId
    @TableId(type = IdType.AUTO)
    @Null(groups = ValidGroup.Crud.Create.class, message = "不需要填写id")
    @NotNull(groups = ValidGroup.Crud.Update.class,message = "id不能为空")
    @NotNull(groups = ValidGroup.Crud.Delete.class,message = "id不能为空")
    private Long id;

    //中文名
    @NotNull(groups = ValidGroup.Crud.Create.class, message = "中文名不能为空")
    @Length(max = 10)
    private String chineseName;
    //英文名
    @NotNull(groups = ValidGroup.Crud.Create.class, message = "英文名不能为空")
    @Length(max = 10)
    private String englishName;

    //简介
    @NotNull(groups = ValidGroup.Crud.Create.class, message = "简介不能为空")
    @Length(max = 100)
    private String des;
    //状态
    @NotNull(groups = ValidGroup.Crud.Create.class, message = "状态不能为空")
    private Integer state;



    public static Dictionary toEntity(DictionaryVO dictionaryVO){


        Dictionary dictionary = new Dictionary();
        dictionary.setId(dictionaryVO.getId());
        dictionary.setChineseName(dictionaryVO.getChineseName());
        dictionary.setEnglishName(dictionaryVO.getEnglishName());
        dictionary.setDes(dictionaryVO.getDes());
        dictionary.setState(dictionaryVO.getState());


        return dictionary;

    }


    public static DictionaryVO toVO(Dictionary dictionary){

        DictionaryVO dictionaryVO = new DictionaryVO();
        dictionaryVO.setId(dictionary.getId());
        dictionaryVO.setChineseName(dictionary.getChineseName());
        dictionaryVO.setEnglishName(dictionary.getEnglishName());
        dictionaryVO.setDes(dictionary.getDes());
        dictionaryVO.setState(dictionary.getState());


        dictionaryVO.setId(dictionary.getId());
        dictionaryVO.setChineseName(dictionary.getChineseName());
        dictionaryVO.setEnglishName(dictionary.getEnglishName());
        dictionaryVO.setDes(dictionary.getDes());
        dictionaryVO.setState(dictionary.getState());


        return dictionaryVO;

    }

}
